package com.scl.calendar;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.scl.reminder.CalendarDataBean;
import com.scl.reminder.CalendarReminder;
import com.scl.reminder.TypeStatus;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;

public class MainActivity extends AppCompatActivity {


    private Button button;
    private Button button1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        /*申请权限  注意清单文件也要添加*/
        XXPermissions.with(this)
                .permission(Permission.READ_CALENDAR)
                .permission(Permission.WRITE_CALENDAR)
                .request(new OnPermissionCallback() {
                    @Override
                    public void onGranted(List<String> permissions, boolean all) {
                        Toast.makeText(MainActivity.this, "权限开启了", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onDenied(List<String> permissions, boolean never) {
                        Toast.makeText(MainActivity.this, "拒接了权限", Toast.LENGTH_SHORT).show();
                    }
                });

        button = findViewById(R.id.button);
        button1 = findViewById(R.id.button1);

        //java
        /*List<CalendarBean> list = new ArrayList<>();
        list.add(new CalendarBean(8, 0,"起床啦，让我们一起开启“高颜值喝水”新模式"));
        list.add(new CalendarBean(14, 0,"到恢复精神的时间了，“水”在等你"));
        list.add(new CalendarBean(16, 0,"来自喝水鱼朋友般呵护提醒，按时喝水哦！"));*/

        //kotlin
        List<CalendarDataBean> list = new ArrayList<>();
       /* list.add(new CalendarDataBean(10, 0, "hah1",false));
        list.add(new CalendarDataBean(16, 0, "hah1",false));
        list.add(new CalendarDataBean(18, 0, "hah1",false));*/


        Calendar mCalendar = Calendar.getInstance();
        //是设置日历的时间，主要是让日历的年月日和当前同步
        mCalendar.setTimeInMillis(System.currentTimeMillis());
        // 这里时区需要设置一下，不然可能个别手机会有8个小时的时间差
        mCalendar.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        //设置在几点提醒  设置的为几点
        mCalendar.set(Calendar.HOUR_OF_DAY, 8);
        //设置在几分提醒  设置的为几分
        mCalendar.set(Calendar.MINUTE, 0);
        //下面这两个看字面意思也知道
        mCalendar.set(Calendar.SECOND, 0);
        mCalendar.set(Calendar.MILLISECOND, 0);

        long sTime = mCalendar.getTimeInMillis();

//        Calendar mCalendar = Calendar.getInstance();
//        //是设置日历的时间，主要是让日历的年月日和当前同步
//        mCalendar.setTimeInMillis(System.currentTimeMillis());
//        // 这里时区需要设置一下，不然可能个别手机会有8个小时的时间差
//        mCalendar.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        //设置在几点提醒  设置的为几点
        mCalendar.set(Calendar.HOUR_OF_DAY, 22);
        //设置在几分提醒  设置的为几分
        mCalendar.set(Calendar.MINUTE, 0);
        //下面这两个看字面意思也知道
        mCalendar.set(Calendar.SECOND, 0);
        mCalendar.set(Calendar.MILLISECOND, 0);

        long eTime = mCalendar.getTimeInMillis();


        List<CalendarDataBean> strings = new ArrayList<>();
       /* strings.add(new CalendarDataBean(10, 0, "hah1",false));
        strings.add(new CalendarDataBean(16, 0, "hah1",false));
        strings.add(new CalendarDataBean(18, 0, "hah1",false));*/


        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                       /* CalendarReminderUtils.addCalendarList(
                                MainActivity.this,
                                list,
                                false,
                                false,
                                "喝水鱼",
                                "友情提示：若要关闭该提醒，请点击「喝水鱼」App->我的->喝水提醒->关闭所有提醒"
                        );*/
                       /* CalendarReminder.INSTANCE.addCalendarList(
                                MainActivity.this,
                                list,
                                false,
                                false,
                                "喝水鱼",
                                "友情提示：若要关闭该提醒，请点击「喝水鱼」App->我的->喝水提醒->关闭所有提醒",
                                ReminderType.TYPE_NUMBER,
                                3
                        );*/

                        CalendarReminder.INSTANCE.addCalendarTimeScope(
                                MainActivity.this,
                                sTime,
                                eTime,
                                1800000,
                                1800000,
                                "描述",
                                strings,
                                "小鱼鱼提醒",
                                true,
                                false,
                                TypeStatus.NUMBER,
                                3
                        );
                    }
                }).start();
            }
        });

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CalendarReminder.INSTANCE.deleteCalendarEvent(
                        MainActivity.this,
                        "小鱼鱼提醒"
                );
            }
        });
    }
}